package offer.easy.math;

public class Power {

    //实现幂函数
    //思考情况：底数具有限制，对指数进行判断
    //1.指数小于0，意味着底数取倒数，指数取绝对值
    //2.指数等于0，值为1
    //3.指数大于0，正常累乘

    public static double pow(double base,int exponent) {
        if (exponent < 0) {
            base = 1/base;
            exponent = -exponent;
        } else if (exponent == 0) {
            return 1;
        }

        double res = base;

        for (int i = 1; i < exponent; i++) {
            res = res*base;
        }

        return res;
    }

    public static void main(String[] args) {
        System.out.print(pow(2, 10));
    }
}
